package org.monkey.common.generator.entity;

import io.swagger.annotations.ApiModel;
import lombok.Data;
import org.monkey.common.constant.entity.MysqlColumnInfo;
import org.monkey.common.constant.util.MonkeyStrUtil;
import org.monkey.common.generator.util.TypeUtil;

@Data
@ApiModel
public class JavaFieldInfo {

  private String filedName;
  private String filedDescription;
  private String defaultValue;
  private String type;
  private boolean nullAble;
  private String columnName;

  public JavaFieldInfo(MysqlColumnInfo mc, boolean hump) {
    this.columnName = mc.getColumnName();
    String name = mc.getColumnName().toLowerCase();
    if (hump) {
      name = MonkeyStrUtil.underlineToHump(name);
    }
    this.filedName = name;
    this.filedDescription = mc.getColumnComment();
    this.defaultValue = mc.getColumnDefault();
    this.nullAble = mc.getIsNullable().toUpperCase().equals("YES");
    this.type = TypeUtil.jdbcTypeToJavaType(mc.getDataType());
  }
}
